<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI

class Home extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('usuario_model', '', TRUE);
        $this->load->model('paginacion_model', '', TRUE);
    }

    function index() {

        if ($this->session->userdata('logged_in')) {
            $cedula = $this->session->userdata('id');
            $this->load->library('form_validation');
            $data['username'] = $this->session->userdata('username');
            $tipo_usuario = $this->session->userdata('tipo');
            $data['cumpleanios'] = $this->usuario_model->getCumpleanieros();
            $data['totalMarcas'] = $this->paginacion_model->getUltimasMarcasPerfil($cedula, TRUE);
            $data['listaMarcas'] = $this->paginacion_model->getUltimasMarcasPerfil($cedula, FALSE);

            $this->load->helper('url');
            $this->load->view('templates/head');

            if ($tipo_usuario == 1) {
                $this->load->view('templates/header');
            } else if ($tipo_usuario == 2) {
                $this->load->view('templates/header_jefe');
            } else {
                $this->load->view('templates/header_usuario');
            }
            $this->load->view('home_view', $data);
            $this->load->view('templates/footer');
        } else {

            //If no session, redirect to login page
            redirect('login', 'refresh');
        }
    }

    function logout() {
        $this->session->unset_userdata('logged_in');
        $this->session->sess_destroy();
        redirect('home', 'refresh');
    }

}

?>